package com.ray.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.bean.ReportBean;
import com.ray.exception.ServiceException;
import com.ray.service.CompanyService;
import com.ray.service.OrderService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;


@Controller
@RequestMapping("company")
public class CompanyController {
	@Autowired
	CompanyService companyService;

	
	@RequestMapping("/checkCpnpany")
	@ResponseBody
	public void checkCpnpany(HttpServletRequest request) throws ServiceException{
		Map map=RequestUtil.getRequestAllParamNotLogin(request);
		companyService.checkCpnpany(map);
	}
	
	@RequestMapping("/registerCompany")
	public Map  registerCompany(HttpServletRequest request) throws ServiceException{
		Map map=RequestUtil.getRequestAllParamNotLogin(request);
		companyService.registerCompany(map);
		return ResponseUtil.ResponseResult("login.html");
	}
	
	/**
	 * 获取所有公司
	 * companyName
	 * @param request
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/getAllCompany")
	public Map  getAllCompany(HttpServletRequest request) throws ServiceException{
		Map map=RequestUtil.getRequestAllParamNotLogin(request);
		return ResponseUtil.ResponseResult(companyService.getAllCompany(map));
	}
	
	/**
	 * 获取公司信息
	 * @param request
	 * @throws ServiceException
	 */
	@RequestMapping("/getCompany")
	@ResponseBody
	public Map getIsUpdate(HttpServletRequest request) throws ServiceException{
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(companyService.getCompany(map));
	}
	
	/**
	 * 获取公司设置的制单输入是否可输
	 * @param request
	 * @param isUpdate
	 * @throws ServiceException
	 */
	@RequestMapping("/setCompany")
	@ResponseBody
	public Map setIsUpdate(HttpServletRequest request) throws ServiceException{
		Map map=RequestUtil.getRequestAllParam(request);
		companyService.setCompany(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.SET_SUCCESS);
	}
	
	
	/**
	 * 设置部门入库方式
	 * @param jsonArray(参数)
	 * @throws ServiceException
	 */
	@RequestMapping("/setDeptInWorkShopMode")
	@ResponseBody
	public Map setDeptInWorkShopMode(HttpServletRequest request) {
		Map map=RequestUtil.getRequestAllParam(request);
		companyService.setDeptInWorkShopMode(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.SET_SUCCESS);
	}
	
	/**
	 * companyName  公司名称
	 * 
	 * 审核公司
	 * @param jsonArray(参数)
	 * @throws ServiceException
	 */
	@RequestMapping("/approvalCompany")
	@ResponseBody
	public Map approvalCompany(HttpServletRequest request) {
		Map map=RequestUtil.getRequestAllParam(request);
		companyService.approvalCompany(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.APPROVAL_SUCCESS);
	}
	

	/**
	 * 获取公司信息
	 * @param request
	 * @throws ServiceException
	 */
	@RequestMapping("/getCompanyByCompanyName")
	@ResponseBody
	public Map getCompanyByCompanyName(String company) throws ServiceException{
		Map map=new HashMap();
		map.put("loginCompany", company);
		return ResponseUtil.ResponseResult(companyService.getCompany(map));
	}
	
	
	/**
	 * 获取公司信息
	 * @param request
	 * @throws ServiceException
	 */
	@RequestMapping("/getMaterialConfig")
	@ResponseBody
	public Map getMaterialConfig(HttpServletRequest request){
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(companyService.getMaterialConfig(map));
	}
	
	
	/**
	 * 设置公司物料名称配置
	 * @param request
	 * @throws ServiceException
	 * jsonArray
	 * materialName  物料名称
	 * adJustInPrice 入库可调整单价范围
	 * adJustInCount 入库可调整数量
	 */
	@RequestMapping("/setMaterialConfig")
	@ResponseBody
	public Map setMaterialConfig(HttpServletRequest request){
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(companyService.setMaterialConfig(map));
	}
	
	
	@RequestMapping("/getCompanyUseDetail")
	@ResponseBody
	public Map getCompanyUseDetail(HttpServletRequest request){
		return ResponseUtil.ResponseResult(companyService.getCompanyUseDetail());
	}
	
	@RequestMapping("/updateComapnyPayEndClockTime")
	@ResponseBody
	public Map updateComapnyPayEndClockTime(HttpServletRequest request){
		Map map=RequestUtil.getRequestAllParam(request);
		companyService.updateComapnyPayEndClockTime(map);
		return ResponseUtil.ResponseResult("修改成功");
	}
	
}
